package com.llkj.contractmanagement.contractmanagement.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.llkj.contractmanagement.R;
import com.llkj.contractmanagement.model.ContractListBean;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * author: dong.yj
 * created on: 2016/8/17 16:46
 * description:
 */
public class FileListAdapter extends CommonBaseAdapter<FileListAdapter.ViewHolder,Map<String, Object>>{


    public FileListAdapter(Context context, ArrayList<Map<String, Object>> list) {
        super(context, list);
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int position) {
        return new ViewHolder(inflate(R.layout.lv_contract_model_item, null));
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        Map<String, Object> map = mList.get(position);
        String fileName = (String) map.get("itemfileName");
        String type = fileName.substring(fileName.lastIndexOf(".") + 1);
        if (type.equals("pdf")) {
            holder.iv_pic.setImageResource(R.drawable.icon_pdf);
        } else if (type.equals("doc")) {
            holder.iv_pic.setImageResource(R.drawable.icon_word);
        }
        holder.tv_contract_name.setText(fileName);
    }

    static class ViewHolder extends CommonBaseAdapter.ViewHolder {

        @Bind(R.id.tv_lv_item_name)
        TextView tv_contract_name;
        @Bind(R.id.iv_lv_item_head)
        ImageView iv_pic;
        public ViewHolder(View view) {
            super(view);
            ButterKnife.bind(view);
        }
    }
}
